package br.com.uniban.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.com.uniban.form.UsuarioForm;

public class LoginAction extends Action {

	public static final String USUARIO_FORM = "UsuarioForm";
	private static final String LOGAR = "logar";
	private static final String LOGADO = "logado";

	

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse response)throws Exception {
		
		UsuarioForm form = (UsuarioForm) request.getSession().getAttribute(USUARIO_FORM);
		if(form.isLogado())
			return mapping.findForward(LOGADO);
		
		form.resetForm();
		return mapping.findForward(LOGAR);

	}
	
}
